import {fromJS} from "immutable";
import * as contants from './constants';

const defaultState=fromJS({
   topicList:[],
    articleList:[],
    recommendList:[],
    articlePage:1,
    showScroll:true
})
// immutable.js ----facebook开发
//先引用 fromJS  将defaultState变成 immutable对象  。调用immutable 的 get set方法


export default (state=defaultState,action)=>{
    switch (action.type) {
        case contants.CHANGE_HOME_DATA:
            return state.merge({
                topicList:fromJS(action.topicList),
                articleList:fromJS(action.articleList),
                recommendList:fromJS(action.recommendList)
            })
        case contants.ADD_HOME_LIST:
            //push方法，是将每一条数据添加到数组中，形成新的数组
            //concat方式。是将数组添加到旧数组中，返回一个新数组
            return state.merge({
                articleList:state.get('articleList').concat(action.list),
                articlePage:action.page
            })
        case contants.TOGGLE_TOP_SHOW:
          return  state.set('showScroll',action.show)
        default:
            return state;
    }
}
